package kr.hkit.powerjava.chapter24.service;

import java.util.Comparator;
import java.util.Scanner;

import kr.hkit.powerjava.chapter24.dao.InterfaceDAO;
import kr.hkit.powerjava.chapter24.vo.Department;
import kr.hkit.powerjava.chapter24.vo.Student;

public class ServiceDepartment extends ServiceItem<Department> {

	public ServiceDepartment(InterfaceDAO<Department> dao, Scanner sc) {
		super(dao, sc);
	}

	@Override
	public Department inputItemInfo(boolean gubun) {
		System.out.print("부서번호 부서명");
		int num = sc.nextInt();
		String name = sc.next();
		if(gubun) {
			System.out.print("위치");
			int floor = sc.nextInt();
			return new Department(num, name, floor);
		} else {
			return new Department(num, name);
		}
	}

	@Override
	public void prnSubMenu() {
		System.out.print("1.이름순 정렬\t2.위치별 정렬\t3.번호순 정렬");
		int subnum = sc.nextInt();
		switch(subnum) {
			case 1:
				dao.prnListItem(new Comparator<Department>() {
				@Override
				public int compare(Department o1, Department o2) {
					return o1.getDeptName().hashCode() - o2.getDeptName().hashCode();
				}
				});
				break;
			case 2:
				dao.prnListItem(new Comparator<Department>() {
					@Override
					public int compare(Department o1, Department o2) {
						return o1.getFloor() - o2.getFloor();
					}
				});
				break;
			case 3:
				dao.prnListItem(null);
				break;
			default:
				break;
		}	
	}
}